#include "Common/Exceptions/ProductException.h"
#include "EditorCore/Actions/MoveAction.h"

using namespace cmn;

namespace editor_core {

	MoveAction::MoveAction( IEntity* entity, Vec2 vector ) :
		m_entity( entity ),
		m_targetVector( vector )
	{}

	bool MoveAction::Commit() {
		m_actualVector = m_entity->Move( m_targetVector );
		return true;
	}

	void MoveAction::Recommit() {
		Vec2 movedBy = m_entity->Move( m_actualVector );
		if( Distance( movedBy, m_actualVector ) >= 0.001f )
			throw ProductException( "Entity moved wrongly!" );
	}

	void MoveAction::Rollback() {
		Vec2 movedBy = m_entity->Move( -m_actualVector );
		if( Distance( movedBy, -m_actualVector ) >= 0.001f )
			throw ProductException( "Entity moved wrongly!" );
	}

}
